/* -----------------------------------------------------------------------
 * test shuffle
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
// based off of testUpdateCoins  example provided for class
    int i;
    int seed = 1000;
    int numPlayer = 2;
    //int maxBonus = 10;
    //int p, r, handCount;
	int r;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    //int maxHandCount = 5;
	
	//int testHandCount;
	int testDeck[MAX_DECK];
	int player = 0;
	int check = 0;
	int failed = 0;
	int j =0;

	
	memset(&G, 23, sizeof(struct gameState));   // clear the game state
	r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
	
	G.deck[player][0] = smithy; //set some kingdom cards for testing
	G.deck[player][1] = village; //set some kingdom cards for testing
	G.deck[player][2] = baron; //set some kingdom cards for testing
	G.deck[player][3] = feast; //set some kingdom cards for testing
	G.deck[player][4] = gardens; //set some kingdom cards for testing
	G.deck[player][5] = mine; //set some kingdom cards for testing
	
	//check deck is different after several calls to shuffle
	for(j=0; j<=10; j++){
		check = 0;
		//copy cardts to test deck
		for(i=0; i<G.deckCount[player+1]; i++){
			testDeck[i] = G.deck[player][i];
		}
		//check player deck and test deck equal
		for(i=0; i<10; i++){
			if(testDeck[i] != G.deck[player][i]){
				check = 1;
				
			}
				
		}
		if(check == 1){
			failed = 1;
			printf("Unittest 1: decks not equal\n");
		}
		
		//shuffle deck and compare to previous deck to ensure they are different		
		shuffle(player, &G);
		check = 0;
		for(i=0; i<10; i++){
			if(testDeck[i] != G.deck[player][i]){
				check = 1;				
			}
					
		}
		if(check == 0){
			failed = 1;
			printf("Unittest 1: decks still same after shuffle\n");
		}
	}

	
	if(failed == 0){
		printf("unittest1: shuffle - All tests passed!\n");
	}

    return 0;
}
